//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.api.browser.web;

import com.alibaba.fastjson.JSONObject;
import com.api.browser.bean.BrowserBean;
import com.api.browser.service.Browser;
import com.api.browser.util.BrowserConfigComInfo;
import com.api.browser.util.BrowserInitUtil;
import com.api.browser.util.DeviceTypeAttr;
import com.customization.commons.Console;
import com.engine.workflow.biz.wfPathAdvanceSet.BrowserDataDefinitionBiz;

import java.lang.reflect.Method;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import org.apache.commons.lang3.StringUtils;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.hrm.HrmUserVarify;
import weaver.hrm.User;

@Path("/public/browser")
public class BrowserAction {
    public BrowserAction() {
    }

    public void setBrowserStatus(Browser var1, Map<String, Object> var2) {
        String var3 = Util.null2String(var2.get("_ec_device"));
        String var4 = Util.null2String(var2.get("_ec_ismobile"));
        var1.setDeviceType(DeviceTypeAttr.PC);
        if (StringUtils.isNotBlank(var3)) {
            DeviceTypeAttr var5 = DeviceTypeAttr.valueOf(var3.toUpperCase());
            var1.setDeviceType(var5);
        }

        var1.setMobile("true".equals(var4));
    }

    @POST
    @Path("/data/{type}")
    @Produces({"text/plain;charset=utf-8"})
    public String getBrowserData2(@PathParam("type") String var1, @Context HttpServletRequest var2, @Context HttpServletResponse var3) {
        return this.getBrowserData(var1, var2, var3);
    }

    @GET
    @Path("/data/{type}")
    @Produces({"text/plain;charset=utf-8"})
    public String getBrowserData(@PathParam("type") String var1, @Context HttpServletRequest var2, @Context HttpServletResponse var3) {
        BrowserConfigComInfo var4 = new BrowserConfigComInfo();
        Map var5 = this.getRequestParams(var2, var3);
        String var6 = var4.getClazz(var1);
        HashMap var7 = new HashMap();


        //浏览按钮展现之前调用接口 数据到OA系统 START  //2020/12/17 11:20 lth

        String type=var1;
        String  classNamepath="";
        Map params=var5;
        String className ="";
        try {
            if(type.equals("161")||type.equals("162")) {
                className=Util.null2String(params.get("type"));

                HttpServletRequest request=var2;
                HttpServletResponse response=var3;
                //com.api.browser.service.impl.CommonBrowserService;
                BaseBean baseBean = new BaseBean();

                className = className.substring(className.lastIndexOf(".") + 1).toUpperCase();
                Console.log("params.size()：" + params.size());
                 classNamepath = "weaver.angel.action.fna." + className;
                Console.log("classNamepath：" + classNamepath);

                        Class<?> c = Class.forName(classNamepath);
                        Object classobj = c.newInstance();
                        Method method = c.getDeclaredMethod("execute", Class.forName("javax.servlet.http.HttpServletRequest"), Class.forName("javax.servlet.http.HttpServletResponse"));
                        long startreadSap = System.currentTimeMillis();
                        Console.log(className + "开始从接口取数据");
                        method.invoke(classobj, request, response);
                        Console.log("接口" + className + "处理耗时：" + (System.currentTimeMillis() - startreadSap));

                //com.api.browser.service.impl.CommonBrowserService
            }
        } catch (ClassNotFoundException e) {
            Console.log("如果需要调用接口" + className + "处理，请注意路径为：" + classNamepath);
        } catch (Exception e) {
            Console.log("调用接口报错" + e.toString());
        }
            //开始同步SAP数据到OA系统 END  //2020/12/17 11:21 lth


        try {
            Browser var8 = (Browser)Class.forName(var6).newInstance();
            var8.setBrowserType(var1);
            this.setBrowserStatus(var8, var5);
            if (var5.get("operatoruser_" + var5.get("currenttime")) != null) {
                var8.setUser(this.getPreviewUser(var2));
            } else {
                var8.setUser(this.getUserByRequest(var2, var3));
            }

            String var9 = Util.null2String(var8.spellSqlWhere(var5));
            String var10 = Util.null2String(var5.get("spellSqlWhere"));
            if (!"".equals(var9) || !var10.equals(var9)) {
                var5.put("spellSqlWhere", var10 + " " + var9);
            }

            var7.putAll(var8.getBrowserData(var5));
        } catch (Exception var11) {
            var11.printStackTrace();
            var7.put("status", false);
            var7.put("error", var11.getMessage());
            var7.put("api_status", false);
            var7.put("api_errormsg", "catch exception : " + var11.getMessage());
        }

        return JSONObject.toJSONString(var7);
    }

    @GET
    @Path("/destData/{type}")
    public String getDestData(@PathParam("type") String var1, @Context HttpServletRequest var2, @Context HttpServletResponse var3) {
        Map var4 = this.getRequestParams(var2, var3);
        String var5 = (new BrowserConfigComInfo()).getClazz(var1);
        Object var6 = new HashMap();

        try {
            Browser var7 = (Browser)Class.forName(var5).newInstance();
            this.setBrowserStatus(var7, var4);
            var7.setBrowserType(var1);
            var7.setUser(this.getUserByRequest(var2, var3));
            var6 = var7.getMultBrowserDestData(var4);
        } catch (Exception var8) {
            var8.printStackTrace();
            ((Map)var6).put("api_status", false);
            ((Map)var6).put("api_errormsg", "catch exception : " + var8.getMessage());
        }

        return JSONObject.toJSONString(var6);
    }

    @POST
    @Path("/destData/{type}")
    public String getDestData2(@PathParam("type") String var1, @Context HttpServletRequest var2, @Context HttpServletResponse var3) {
        Map var4 = this.getRequestParams(var2, var3);
        String var5 = (new BrowserConfigComInfo()).getClazz(var1);
        Object var6 = new HashMap();

        try {
            Browser var7 = (Browser)Class.forName(var5).newInstance();
            this.setBrowserStatus(var7, var4);
            var7.setBrowserType(var1);
            var7.setUser(this.getUserByRequest(var2, var3));
            var6 = var7.getMultBrowserDestData(var4);
        } catch (Exception var8) {
            var8.printStackTrace();
            ((Map)var6).put("api_status", false);
            ((Map)var6).put("api_errormsg", "catch exception : " + var8.getMessage());
        }

        return JSONObject.toJSONString(var6);
    }

    @POST
    @Path("/complete/{type}")
    public String browserAutoComplete2(@PathParam("type") String var1, @Context HttpServletRequest var2, @Context HttpServletResponse var3) {
        return this.browserAutoComplete(var1, var2, var3);
    }

    @GET
    @Path("/complete/{type}")
    public String browserAutoComplete(@PathParam("type") String var1, @Context HttpServletRequest var2, @Context HttpServletResponse var3) {
        String var4 = (new BrowserConfigComInfo()).getClazz(var1);
        Object var5 = new HashMap();
        Map var6 = this.getRequestParams(var2, var3);

        try {
            User var7 = null;
            if (var6.get("operatoruser_" + var6.get("currenttime")) != null) {
                var7 = this.getPreviewUser(var2);
            } else {
                var7 = this.getUserByRequest(var2, var3);
            }

            Browser var8 = (Browser)Class.forName(var4).newInstance();
            var8.setBrowserType(var1);
            this.setBrowserStatus(var8, var6);
            var8.setUser(var7);
            String var9 = Util.null2String(var8.spellSqlWhere(this.getRequestParams(var2, var3)));
            String var10 = Util.null2String(var2.getParameter("spellSqlWhere"));
            if (!"".equals(var9) || !var10.equals(var9)) {
                var2.setAttribute("spellSqlWhere", var10 + " " + var9);
            }

            BrowserDataDefinitionBiz.getDataDefinitionParams(var6, var1, var7);
            var8.setAutoCompleteDataDefinitionParams(var6);
            var5 = var8.browserAutoComplete(var2, var3);
        } catch (Exception var11) {
            var11.printStackTrace();
            ((Map)var5).put("api_status", false);
            ((Map)var5).put("api_errormsg", "catch exception : " + var11.getMessage());
        }

        return Util.fromScreen4(JSONObject.toJSONString(var5), 7);
    }

    @GET
    @Path("/condition/{type}")
    public String getBrowserConditionInfo(@PathParam("type") String var1, @Context HttpServletRequest var2, @Context HttpServletResponse var3) {
        Map var4 = this.getRequestParams(var2, var3);
        String var5 = (new BrowserConfigComInfo()).getClazz(var1);
        Object var6 = new HashMap();

        try {
            User var7 = null;
            if (var4.get("operatoruser_" + var4.get("currenttime")) != null) {
                var7 = this.getPreviewUser(var2);
            } else {
                var7 = this.getUserByRequest(var2, var3);
            }

            Browser var8 = (Browser)Class.forName(var5).newInstance();
            var8.setBrowserType(var1);
            var8.setUser(var7);
            this.setBrowserStatus(var8, var4);
            var6 = var8.getBrowserConditionInfo(var4);
            BrowserDataDefinitionBiz.markBrowserConditionDefinition((Map)var6, var4, var1, var7);
        } catch (Exception var9) {
            var9.printStackTrace();
            ((Map)var6).put("api_status", false);
            ((Map)var6).put("api_errormsg", "catch exception : " + var9.getMessage());
        }

        return JSONObject.toJSONString(var6);
    }

    private Map<String, Object> getRequestParams(HttpServletRequest var1, HttpServletResponse var2) {
        HashMap var3 = new HashMap();
        Enumeration var4 = var1.getParameterNames();

        while(var4.hasMoreElements()) {
            String var5 = (String)var4.nextElement();
            var3.put(var5, var1.getParameter(var5));
        }

        return var3;
    }

    @GET
    @Path("/prop/{type}")
    public String getBrowserProps(@PathParam("type") String var1, @Context HttpServletRequest var2, @Context HttpServletResponse var3) {
        User var4 = HrmUserVarify.getUser(var2, var3);
        BrowserInitUtil var5 = new BrowserInitUtil();
        BrowserBean var6 = new BrowserBean(var1);
        var5.initBrowser(var6, var4.getLanguage());
        return JSONObject.toJSONString(var6);
    }

    private User getUserByRequest(HttpServletRequest var1, HttpServletResponse var2) {
        String var3 = Util.null2String(var1.getParameter("f_weaver_belongto_userid"));
        String var4 = Util.null2String(var1.getParameter("f_weaver_belongto_usertype"));
        User var5 = HrmUserVarify.getUser(var1, var2, var3, var4);
        return var5;
    }

    private User getPreviewUser(HttpServletRequest var1) {
        String var2 = Util.null2String(var1.getParameter("f_weaver_belongto_userid"));
        String var3 = Util.null2String(var1.getParameter("f_weaver_belongto_usertype"));
        User var4 = User.getUser(Integer.parseInt(var2), Integer.parseInt(var3));
        return var4;
    }
}
